from django.db import models
from django.contrib.auth.models import AbstractUser


# Create your models here.
class User(AbstractUser):
    username = models.CharField(max_length=32,unique=True)
    password = models.CharField(max_length=255)
    mobile = models.CharField(max_length=24)
    weixinid = models.CharField(max_length=24)
    email = models.CharField(max_length=64)
    role = models.ManyToManyField(to='Role',null=True)

    class Meta:
        db_table = 'user'


# 角色表（部门leader、运维组、安全组、ops）
class Role(models.Model):
    zh_name = models.CharField(max_length=32)
    name = models.CharField(max_length=32)
    description = models.CharField(max_length=32)

    def __str__(self):
        return self.zh_name

# 部门表：自关联一对多可以去除
class Department(models.Model):
    name = models.CharField(max_length=64)
    fid = models.ForeignKey('self',on_delete=models.CASCADE, null=True, blank=True)  # 上级部门id
    user = models.ManyToManyField(to='User',null=True)

    def __str__(self):
        return self.name


